<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>5s跳转到百度</title>
    <style>
        body{
            font-size: 30px;
        }
        p{
            text-align: center;
        }
        span{
            color: red;
        }
    </style>
</head>
<body>
    <p>
        即将跳转,还有<span id="time">5</span>秒...
    </p>
</body>
<script>
    //设置倒数事件
    let num = 5;

    //设置循环计时器
    let interval = setInterval("count()",1000);
    //let timeout = setTimeout("count",5000);     //一次性定时器
    //clearTimeout(timeout);        //清除一次性定时器

    //设置计时函数
    function count() {
        num--;
        if(num<=0){
            location.href="http://www.baidu.com";
            // clearInterval(interval); //清除循环定时器
        }
        document.getElementById("time").innerText=num;
    }

</script>
</html>